package com.itheima.thread.Demo8_阻塞队列;

import java.util.concurrent.ArrayBlockingQueue;

public class Cooker extends Thread{
    /*
    生产者类(Cooker)：实现Runnable接口，重写run()方法，设置线程任务
    1.构造方法中接收一个阻塞队列对象
    2.在run方法中循环向阻塞队列中添加包子
    3.打印添加结果
     */
    private ArrayBlockingQueue<String> bq;

    public Cooker(ArrayBlockingQueue<String> bq) {
        this.bq = bq;
    }

    @Override
    public void run() {
        while(true){
            try {
                bq.put("汉堡包");
                Thread.sleep(100);
                System.out.println("厨师做好了一个汉堡包");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
